def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True
    
def closest_prime_number(word1, word2, word3):
    numbers = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
    
    number = numbers[word1]*100 + numbers[word2]*10 + numbers[word3]
    
    if 100 <= number <= 999 and is_prime(number):
        print(number)
        return
    
    while True:
        number += 1
        if is_prime(number):
            print(number)
            return
    
        number -= 2
        if is_prime(number):
            print(number)
            return
    
words = input().split()
if len(words) != 3:
    print("Wrong input")
else:
    closest_prime_number(words[0], words[1], words[2])
